
var ison = false;
var isoff= false;
var lp_over = true;
var count1=0;
var count2=0;



//主窗体（a1）鼠标点击事件
function fa1_doclick(event){
	if (event.target != this){
        console.log('fa1_doclick不是本身',event);
		var c1 =document.getElementById("c1");
		c1.innerHTML = "fa1_doclick不是本身";
	}else{
        console.log('fa1_doclick 是本身',event);
		var c1 =document.getElementById("c1");
		c1.innerHTML = "fa1_doclick 是本身";
	}
}

//主窗体（a1）鼠标移动事件
function fa1_domove(event){
	//console.log(event); 
	if (event.target != this){
		console.log('fa1_domove不是本身',event);
	}else{
		console.log('fa1_domove是本身',event);
		let myH = event.target.offsetHeight; 
		let myW = event.target.offsetWidth; 
		//if (myW<20) myW=20;
		let laX = event.layerX; //基于本事件主体的坐标系
		let laY = event.layerY; //基于本事件主体的坐标系
		let bIn = false;
		if (laX>=myW*0.015 && laX <= myW*0.985 ) {
			if (laY>=myH*0.95 && laY <= (myH-4)){
				bIn = true;
			};
		};
		count1++;
		var c1 =document.getElementById("c1");
		c1.innerHTML = "a1事件计数:"+count1;
		var n1 =document.getElementById("n1");
		n1.innerHTML = event.target.id+',laX:'+laX+',laY:'+laY
		  +',myH:'+myH+',myW:'+myW+',bIn:'+bIn
		  +',isoff:'+isoff+',ison:'+ison;

		var n2 =document.getElementById("n2");
		if (bIn && (!ison)){
			fsetcome();
			n2.innerHTML = 'a1-fsetcome';
		};
		if ((!bIn) && (!isoff)){
			fsetout();
			n2.innerHTML = 'a1-fsetout';
		};
	}    
}

//摸似阻挡层（zd1）鼠标移动事件
function fzd1_domove(event){
	//console.log(ezdvent); 
	if (event.target != this){
		console.log('fzd1_domove不是本身',event);
	}else{
		console.log('fzd1_domove是本身',event);
        let scH = screen.availHeight;
        let dtH = Math.floor(scH*0.05);
		let myH = event.target.offsetHeight; 
		let myW = event.target.offsetWidth; 
        
        let dbt = 4; //弹性区距底4px
        let miH = myH-dbt-dtH;
        let mxH = myH-dbt-2;
		//
		let laX = event.layerX; //基于本事件主体的坐标系
		let laY = event.layerY; //基于本事件主体的坐标系
		let bIn = false;
		let bOut = false;
		if (laX>=1 && laX <= (myW-1) ) {
			if (laY > miH && laY < mxH ){
				bIn = true;
			};
			if (laY < miH || laY > mxH ){
				bOut = true;
			};
		};
		count1++;
		var c1 =document.getElementById("c1");
		c1.innerHTML = "zd1事件计数:"+count1;
		var n1 =document.getElementById("n1");
		n1.innerHTML = event.target.id+',laX:'+laX+',laY:'+laY
		  +',myH:'+myH+',myW:'+myW+',bIn:'+bIn
		  +',isoff:'+isoff+',ison:'+ison+',scH:'+scH+',miH:'+miH+',mxH:'+mxH;

		var n2 =document.getElementById("n2");
		if (bIn && (!ison)){
			fsetcome();
			n2.innerHTML = 'zd1-fsetcome';
		};
		if ((bOut) && (!isoff)){
			fsetout();
			n2.innerHTML = 'zd1-fsetout';
		};
	}    
}

function fsetcome(){
	ison = true;
	var zb1 =document.getElementById("zb1");
	zb1.className = "zb1_panel";
	isoff = false;
	lp_over = false;
}

function fsetout(){
	isoff = true;
	var zb1 =document.getElementById("zb1");
	zb1.className = "zb1_panel_out";
	ison = false;
	lp_over=true;
}


function fzb1_doclick(event){
	if (event.target != this){
        console.log('fzb1_doclick不是本身',event);
		var c1 =document.getElementById("c1");
		c1.innerHTML = "fzb1_doclick不是本身";
	}else{
        console.log('fzb1_doclick 是本身',event);
		var c1 =document.getElementById("c1");
		c1.innerHTML = "fzb1_doclick 是本身";
	}
}

function fzb1_domove(event){
	//console.log(event); 
	if (event.target != this){
	//	console.log('fdolp_move2不是本身',event);
	}else{
		//console.log('fdolp_move2是本身',event);
        let scH = screen.availHeight;
		let myH = event.target.offsetHeight; 
		let myW = event.target.offsetWidth; 
		if (myW<20) myW=20;
		let laX = event.layerX; //基于本事件主体的坐标系
		let laY = event.layerY; //基于本事件主体的坐标系
		let bIn = false;
		if (laX>=1 && laX <= myW-1){
			if (laY>=1 && laY <= myH-1){
				bIn = true;
			};
		};
		count1++;
		var c1 =document.getElementById("c1");
		c1.innerHTML = "zb1事件计数:"+count1;
		var n1 =document.getElementById("n1");
		n1.innerHTML = event.target.id+',laX:'+laX+',laY:'+laY
		  +',myH:'+myH+',myW:'+myW+',bIn:'+bIn
		  +',isoff:'+isoff+',ison:'+ison+',scH:'+scH+',scH*5%:'+Math.floor(scH*0.05)+',myH:'+myH;

		var n2 =document.getElementById("n2");
        n2.innerHTML = 'inner zb1';
		if (bIn && (!ison)){
			//fsetcome();
			//n2.innerHTML = 'fsetcome';
		};
		if ((!bIn) && (!isoff)){
			//fsetout();
			//n2.innerHTML = 'fsetout';
		};
	}
}
function fzb1_doout(event){
	if (event.target != this){
		console.log('fdolp_out2不是本身',event);
	}else{
		console.log('fdolp_out2是本身',event);
        let scH = screen.availHeight;
		let myH = event.target.offsetHeight; 
		let myW = event.target.offsetWidth; 
		let laX = event.layerX; //基于本事件主体的坐标系
		let laY = event.layerY; //基于本事件主体的坐标系
		let bIn = false;
		if (laX>1 && laX < myW-4){
			if (laY>1 && laY < myH-1){
				bIn = true;
			};
		};
		var n1 =document.getElementById("n1");
		n1.innerHTML = event.target.id+',laX:'+laX+',laY:'+laY
		  +',bIn:'+bIn+',scH:'+scH+',myH:'+myH;
		var n2 =document.getElementById("n2");
		if (!bIn ){
            if (myH >= scH*0.04){
		      fsetout();
			  n2.innerHTML = 'zb1-fsetout';
            };
		}
	}
}


function finit(event){
	console.log("finit");
 	var a1 =document.getElementById("a1");
    a1.addEventListener("click",fa1_doclick,true); //useCapture，可选。布尔值，指定事件是否在捕获或冒泡阶段执行。true - 事件句柄在捕获阶段执行
    a1.addEventListener("mousemove",fa1_domove,true);
 	var zd1 =document.getElementById("zd1");
    zd1.addEventListener("mousemove",fzd1_domove,true);

	var zb1 =document.getElementById("zb1");
	zb1.addEventListener("click",fzb1_doclick,true);
	zb1.addEventListener("mousemove",fzb1_domove,true);
	zb1.addEventListener("mouseout",fzb1_doout,true);
    
    var zbitm4=document.getElementById("zbitm4");
    zbitm4.addEventListener("click",zbitmclick,true); 
    
}

window.onload= function(){
	console.log("window.onload");
	finit();	
}

function zbitmclick(event){
    debugger
    if (event==null){
        console.log('event is null');
		var itminfo =document.getElementById("itminfo");
		itminfo.innerHTML = "event is null";
    }else{
	if (event.target != this){
        console.log('event.target不是this',event);
        let sid = event.target.id;
        if (sid==null) sid="(null)";
        let stx = event.target.innerText;
        if (stx==null) stx="(null)";
		var itminfo =document.getElementById("itminfo");
		itminfo.innerHTML = "event.target不是this,target.id:"+sid+",Text:"+stx;
	}else{
        console.log('event.target 是this',event);
        let sid = event.target.id;
        if (sid==null) sid="(null)";
        let stx = event.target.innerText;
        if (stx==null) stx="(null)";
		var itminfo =document.getElementById("itminfo");
		itminfo.innerHTML = "event.target 是this,target.id:"+sid+",Text:"+stx;
	}
    }
}
